{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "16f8fbc7",
   "metadata": {},
   "source": [
    "关键点：用户输入（input输入进来的数据是字符串）、打印（print、占位符、format）、列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9d26fe55",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2021-10-25T08:14:18.948894Z",
     "start_time": "2021-10-25T08:14:18.926832Z"
    }
   },
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "unexpected character after line continuation character (Temp/ipykernel_1144/2134567931.py, line 55)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"C:\\Users\\ZHOUXI~1\\AppData\\Local\\Temp/ipykernel_1144/2134567931.py\"\u001b[1;36m, line \u001b[1;32m55\u001b[0m\n\u001b[1;33m    print(\"您的购物车：\"\\n,shopping_list)\u001b[0m\n\u001b[1;37m                                  ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m unexpected character after line continuation character\n"
     ]
    }
   ],
   "source": [
    "#制定商品列表【{名称、价格}两个属性】\n",
    "#用户输入【input】\n",
    "#打印商品信息、打印商品的次数是由商品列表的长度决定\n",
    "#===============================目标一、 录入商品================================\n",
    "good_list=[\n",
    "    [\"火鸡面\",6],#商品的样式：[商品名称，商品价格]\n",
    "    [\"王中王\",2],\n",
    "    [\"爽口豆干\",1.5],\n",
    "    [\"百事可乐\",3.5],\n",
    "    [\"可口可乐\",3.5],\n",
    "    [\"冰红茶\",3],\n",
    "    [\"绿茶\",3.5],\n",
    "]\n",
    "#------------写到某一步发现前面需要内容优化增加\n",
    "shopping_list = []#用户列表初始为空，后续使用append\n",
    "\n",
    "\n",
    "#录入支付宝余额\n",
    "money = int(input(\"请输入您支付宝余额：\"))#可用手段获取\n",
    "while True:\n",
    "\n",
    "    #写出商品单【打印商品信息】\n",
    "    #---------------------------------：错误部分：----------------------------------------------\n",
    "    # shopping_list = []\n",
    "\n",
    "    # lists = '''---------- list of shopping ----------'''\n",
    "    # for number in good_list:\n",
    "    #     \"商品编号：%s,商品名称：%s,商品价格：%s \n",
    "\n",
    "    # -----------------------------------修改----------------------------------------------\n",
    "    for i in range(len(good_list)):\n",
    "        #先写格式化的样式\n",
    "        print(\"商品编号：%s,商品名称：%s,商品价格：%s\"%(i,good_list[i][0],good_list[i][1]))\n",
    "\n",
    "\n",
    "    #=================================目标二：用户购买================================\n",
    "    #让用户输入商品编号进行购买\n",
    "    choice = input(\"购买商品的编号（如要退出请按“q”）：\")\n",
    "    if choice.isdigit():#isdigit判断是否是数值\n",
    "        choice = int(choice)\n",
    "\n",
    "    #判断：\n",
    "        if choice >= len(good_list):\n",
    "            print(\"您输入的商品不存在，请重新输入\")\n",
    "        else:\n",
    "            #两件事情【用户余额商品价格关系】\n",
    "            if money >= good_list[choice][1]:\n",
    "                money = money - good_list[choice][1]\n",
    "                shopping_list.append(good_list[choice])\n",
    "                print(\"【%s】已经加入您的购物车，您的余额还有{%s}元\"%(good_list[choice][0],money))\n",
    "            else:\n",
    "                print(\"您的余额不足以购买，请更换支付方式\")\n",
    "    elif choice == \"q\":\n",
    "        #如果输入q则说明用户要退出购买了，我们将打印用户已购买了的商品列表与用户余额\n",
    "        print(\"您的购物车：\",shopping_list)\n",
    "        print(\"您的账户余额：%s\"%(money))\n",
    "        break\n",
    "    else:\n",
    "        print(\"请输入正确的【商品编码】，或者按照输入提示进行输入！\")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5ddf6790",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.4"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
